home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / handson / handson.exe / TEST1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-02-04  |  1.9 KB  |  69 lines

  1. unit Test1;
  2. { PC Plus sample program.                                                      }
  3. { illustrates two ways of loading a text file:                                 }
  4. {  1) using standard Pascal procedures and Readln                              }
  5. {  2) using built-in Delphi methods and LoadFromFile                           }
  6. {                                                                              }
  7. { LoadFromFile is simpler to use and faster to load                            }
  8. { Readln (or Read), however, gives the programmer more control                 }
  9.  
  10. interface
  11.  
  12. uses
  13.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  14.   Forms, Dialogs, StdCtrls;
  15.  
  16. type
  17.   TForm1 = class(TForm)
  18.     Memo1: TMemo;
  19.     Button1: TButton;
  20.     Button2: TButton;
  21.     procedure Button1Click(Sender: TObject);
  22.     procedure Button2Click(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.DFM}
  35.  
  36. procedure TForm1.Button1Click(Sender: TObject);
  37. { Traditional Pascal text file reading }
  38. var
  39.    InputFile : TextFile;
  40.    Line      : string;
  41. begin
  42.   Memo1.Lines.Clear;
  43.   if not FileExists( 'Test1.pas' ) then     { Check that input file exists }
  44.      ShowMessage('File: Test1.pas not found!')
  45.   else
  46.   begin
  47.    AssignFile(InputFile, 'Test1.pas');
  48.    Reset(InputFile);
  49.    while not Eof(InputFile) do
  50.    begin
  51.      Readln(InputFile, Line);
  52.      Memo1.Lines.Add(Line);
  53.    end;
  54.    CloseFile(InputFile);
  55.   end
  56. end;
  57.  
  58. procedure TForm1.Button2Click(Sender: TObject);
  59. { Delphi's LoadFromFile file reading method }
  60. begin
  61.    Memo1.Lines.Clear;
  62.    if not FileExists( 'Test1.pas' ) then     { Check that input file exists }
  63.       ShowMessage('File: Test1.pas not found!')
  64.    else
  65.     Memo1.Lines.LoadFromFile('Test1.pas');
  66. end;
  67.  
  68. end.
  69.